local s15__tuxi = fk.CreateSkill {
  name = "s15__tuxi",
}

Fk:loadTranslationTable {
  ["s15__tuxi"] = "突袭",
  [":s15__tuxi"] = "摸牌阶段结束时，你可以弃置至多两张手牌，然后选择等量名其他角色，获得这些角色各一张手牌。",

  ["#s15__tuxi-discard"] = "突袭：请弃置至多两张手牌",
  ["#s15__tuxi-choose"] = "突袭：请选择至多等量名其他角色，获得其各一张手牌",
}

s15__tuxi:addEffect(fk.AfterDrawNCards, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(s15__tuxi.name) and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToCards(player, {
      min_num = 1,
      max_num = 2,
      include_equip = true,
      skill_name = s15__tuxi.name,
      prompt = "#s15__tuxi-discard",
      cancelable = true,
    })
    if #cards == 0 then
      return false
    end
    self.cost_data = cards
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = self.cost_data

    -- 弃置手牌
    room:throwCard(cards, s15__tuxi.name, player, player)

    -- 获取可选择的目标
    local targets = table.filter(room:getOtherPlayers(player, false), function(p)
      return not p:isKongcheng()
    end)

    if #targets == 0 then
      return
    end

    -- 选择目标角色
    local result = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = #cards,
      targets = targets,
      skill_name = s15__tuxi.name,
      prompt = "#s15__tuxi-choose::" .. #cards,
      cancelable = true,
    })

    -- 获得手牌
    for _, p in ipairs(result) do
      if not p:isKongcheng() then
        local hand_cards = p.player_cards[Player.Hand]
        if #hand_cards > 0 then
          local card_id = hand_cards[math.random(1, #hand_cards)]
          room:obtainCard(player, card_id, false, fk.ReasonPrey)
        end
      end
    end
  end,
})

return s15__tuxi
